package com.itheima.manager;

import com.itheima.domain.PmsBrand;
import com.itheima.service.db.PmsBrandService;
import com.itheima.util.R;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PmsBrandManager {

    @DubboReference
    PmsBrandService pmsBrandService;


    /**
     * 根据品牌名称分页获取品牌列表
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public R findByPage(Integer pageNum, Integer pageSize, String keyword) {

        return R.success(pmsBrandService.findByPage(pageNum, pageSize, keyword));
    }

    /**
     * 添加品牌
     * @param pmsBrand
     * @return
     */
    public R addBrand(PmsBrand pmsBrand) {
        Boolean res = pmsBrandService.addBrand(pmsBrand);
        return res ? R.success("品牌添加成功") : R.error(500, "该品牌名称已存在");
    }

    /**
     * 批量删除品牌
     * @param ids
     * @return
     */
    public R deleteBrands(List<Long> ids) {
        pmsBrandService.deleteBrands(ids);
        return R.success("删除成功!");
    }

    /**
     * 获取全部品牌列表
     * @return
     */
    public R findAllBrand() {
        List<PmsBrand> brands = pmsBrandService.findAllBrand();
        return R.success(brands);
    }

    /**
     * 批量更新厂家制造商状态
     * @param factoryStatus
     * @param ids
     * @return
     */
    public R updateFactoryStatus(Integer factoryStatus, List<Long> ids) {
        pmsBrandService.updateFactoryStatus(factoryStatus,ids);
        return R.success("批量更新厂家制造商状态成功");
    }

    /**
     * 批量更新显示状态
     * @param showStatus
     * @param ids
     * @return
     */
    public R updateShowStatus(Integer showStatus, List<Long> ids) {
        pmsBrandService.updateShowStatus(showStatus,ids);
        return R.success("批量更新显示状态成功");
    }

    /**
     * 更新品牌
     * @param pmsBrandParam
     * @return
     */
    public R updateBrandById(PmsBrand pmsBrandParam) {
        Boolean res = pmsBrandService.updateBrandById(pmsBrandParam);
        return res ? R.success("品牌更新成功") : R.error(500, "该品牌名称已存在");
    }

    /**
     * 根据编号查询品牌信息
     * @param id
     * @return
     */
    public R findBrandById(Long id) {
        PmsBrand pmsBrand = pmsBrandService.findBrandById(id);
        return R.success(pmsBrand);
    }
}
